import { getMsbdList, DelMsbdList, AddMsbdList, UpdateMsbdList } from "../api/msbd"


let state = {
    list: [],
    classify: [],
    pageSize: 10,
    currentPage: 1,
    total: 0,
    iptVal: ""
}

let mutations = {
    SET_LIST(state, list) {
        state.list = list
    },
    SET_CLASSIFY(state, classify) {
        state.classify = classify
    },
    SET_PAGESIZE(state, pagesize) {
        state.pageSize = pagesize
    },
    SET_CURRENTPAGE(state, currentpage) {
        state.currentPage = currentpage
    },
    SET_TOTAL(state, total) {
        state.total = total
    },
    SET_IPTVAL(state, iptVal) {
        console.log(iptVal)
        state.iptVal = iptVal
    }
}

let actions = {
    async GetList({ state, commit }) {
        let r = await getMsbdList({
            pageSize: state.pageSize,
            currentPage: state.currentPage - 1,
            total: state.total,
            query: state.iptVal
        });
        commit("SET_LIST", r.data.data)
        commit("SET_CLASSIFY", r.data.classify)
        commit("SET_TOTAL", r.data.total)
    },
    async DelList({ }, id) {
        await DelMsbdList({ id })
    },
    async AddList({ }, form) {
        await AddMsbdList(form)
    },
    async UpdateList({ }, data) {
        await UpdateMsbdList({ ...data })
    }
}

let getters = {

}


let msbd = {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}


export default msbd